package com.lujieni.nio.c1;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class TestFileCopy {

    public static void main(String[] args) throws IOException {
        String source = "D:\\迅雷下载";

        String target = "D:\\迅雷下载拷贝";


        Files.walk(Paths.get(source)).forEach(e->{

            try {
                String nowName = e.toString().replace(source, target);

                // 创建目录
                if(Files.isDirectory(e)){
                    Files.createDirectories(Paths.get(nowName));
                }

                // 是文件 就拷贝文件
                if(Files.isRegularFile(e)){
                    Files.copy(e, Paths.get(nowName));
                }
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });

    }
}
